#include<bits/stdc++.h>
#define M 100005
using namespace std;
int n, m, L, V, d[M], v[M], a[M], p[M], tot;
pair<int, int> seq[M];
double eps = 1e-6;
bool check(int id, int ps)
{
    double now = sqrt(1.0 * v[id] * v[id] + 2.0 * a[id] * (p[ps] - d[id]));
    if(now > 1.0 * V + eps) return 1;
    return 0;
}
bool cmp(pair<int, int> x, pair<int, int> y)
{
    if(x.second != y.second) return x.second < y.second;
    return x.first < y.first;
}
void solve()
{
    scanf("%d%d%d%d", &n, &m, &L, &V);
    for(int i = 1; i <= n; i++) scanf("%d%d%d", &d[i], &v[i], &a[i]);
    for(int i = 1; i <= m; i++) scanf("%d", &p[i]);
    int cnt = 0;
    tot = 0;
    for(int i = 1; i <= n; i++)
    {
        if(d[i] > p[m]) continue;
        if(a[i] == 0)
        {
            int ps = lower_bound(p + 1, p + m + 1, d[i]) - p;
            if(v[i] > V) seq[++tot] = {ps, m}, cnt++;
        }
        else if(a[i] < 0)
        {
            int ps = lower_bound(p + 1, p + m + 1, d[i]) - p;
            int l = ps, r = m, mid, ans = -1;
            while(l <= r)
            {
                mid = (l + r) >> 1;
                if(check(i, mid)) ans = mid, l = mid + 1;
                else r = mid - 1;
            }
            if(~ans) seq[++tot] = {ps, ans}, cnt++;
        }
        else if(a[i] > 0)
        {
            int ps = lower_bound(p + 1, p + m + 1, d[i]) - p;
            int l = ps, r = m, mid, ans = -1;
            while(l <= r)
            {
                mid = (l + r) >> 1;
                if(check(i, mid)) ans = mid, r = mid - 1;
                else l = mid + 1;
            }
            if(~ans) seq[++tot] = {ans, m}, cnt++;
        }
        //cout << seq[tot].first << " " << seq[tot].second << endl;
    }
    printf("%d ", cnt);
    int maxr = 0, num = 0;
    sort(seq + 1, seq + tot + 1, cmp);
    for(int i = 1; i <= tot; i++)
    {
        if(maxr < seq[i].first) maxr = seq[i].second, num++;
        //cout << seq[i].first << " " << seq[i].second << endl;
    }
    printf("%d\n", m - num);
}
signed main()
{
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    int T;
    scanf("%d", &T);
    while(T--) solve();
    return 0;
}
